package com.kimho.core;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
/**
 * 封装分页信息
 * 
 * @author zsd
 *
 */
public class PageInfo {

	private int limit;
	private int start;
	private Map<String, Object> param;
	/**
	 * 
	 * @param key   sql配置文件  #param.key即可以取到value
	 * @param value  key对应的value值
	 */
	public void setQueryParam(String key, Object value) {
		if(param==null){
			param = new HashMap<String, Object>();
		}
		param.put(key, value);
	}
	@SuppressWarnings("unused")
	private PageInfo(){
		
	}
	public PageInfo(HttpServletRequest request){
		Logger log = Logger.getLogger(this.getClass());
		try {
			this.limit = Integer.parseInt(request.getParameter("limit"));
			this.start =  Integer.parseInt(request.getParameter("start"));
		} catch (NumberFormatException e) {
			log.info("分页信息不正确!   分页参数默认0,到integer最大值");
			this.limit=Integer.MAX_VALUE;
			this.start=0;
		}catch (NullPointerException e) {
			log.info("request参数为空!   分页参数默认0,到integer最大值");
			this.limit=Integer.MAX_VALUE;
			this.start=0;
		}catch (Exception e) {
			this.limit=Integer.MAX_VALUE;
			this.start=0;
			log.info("分页信息错误!  分页参数默认0,到integer最大值");
		}
	}
	/**
	 * 每页多少条记录
	 * @return
	 */
	public int getLimit() {
		return limit;
	}
	public void setLimit(String limit) {
		this.limit = Integer.parseInt(limit);
	}
	/**
	 * 从多少条记录开始
	 * @return
	 */
	public int getStart() {
		return start;
	}
	public void setStart(String start) {
		this.start = Integer.parseInt(start);
	}
	
}
